public class Solution {
    public static int search(int [] array ,int start, int end, int k){
        if(start>=end){
            return -1;
        }
        int mid = (end+start)/2 ;
        if(array[mid]<k)
            search(array,start,mid,k);
        if(array[mid]>k)
            search(array,mid+1,end,k);
        return mid;
    }
    public static int GetNumberOfK(int [] array , int k) {
        int result = 0;
        int index = search(array,0,array.length,k);
        if(index==-1){
            return 0;
        }
        int left = index;
        int right = index+1;

        while(left>=0 && array[left]==k ){
            left -=1;
            result++;
        }
        while(right<array.length && array[right++]==k){
            result++;
        }
        return  result;
    }
    public static void main(String args[]){
        int[] a={1,3,3,3,3,4,5};
        System.out.println(GetNumberOfK(a,2));
    }

}

